import defaultSettings from './defaultSettings'; // https://umijs.org/config/
import slash from 'slash2';
import themePluginConfig from './themePluginConfig';

const { pwa } = defaultSettings; // preview.pro.ant.design only do not use in your production ;
// preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。

const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION } = process.env;
const isAntDesignProPreview = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site';
const plugins = [
  [
    'umi-plugin-react',
    {
      antd: true,
      dva: {
        hmr: true,
      },
      locale: {
        // default false
        enable: true,
        // default zh-CN
        default: 'zh-CN',
        // default true, when it is true, will use `navigator.language` overwrite default
        baseNavigator: true,
      },
      dynamicImport: {
        loadingComponent: './components/PageLoading/index',
        webpackChunkName: true,
        level: 3,
      },
      pwa: pwa
        ? {
            workboxPluginMode: 'InjectManifest',
            workboxOptions: {
              importWorkboxFrom: 'local',
            },
          }
        : false, // default close dll, because issue https://github.com/ant-design/ant-design-pro/issues/4665
      // dll features https://webpack.js.org/plugins/dll-plugin/
      // dll: {
      //   include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
      //   exclude: ['@babel/runtime', 'netlify-lambda'],
      // },
    },
  ],
  [
    'umi-plugin-pro-block',
    {
      moveMock: false,
      moveService: false,
      modifyRequest: true,
      autoAddMenu: true,
    },
  ],
];

if (isAntDesignProPreview) {
  // 针对 preview.pro.ant.design 的 GA 统计代码
  plugins.push([
    'umi-plugin-ga',
    {
      code: 'UA-72788897-6',
    },
  ]);
  plugins.push(['umi-plugin-antd-theme', themePluginConfig]);
}

export default {
  plugins,
  hash: true,
  targets: {
    ie: 11,
  },
  // umi routes: https://umijs.org/zh/guide/router.html
  routes: [
    {
      path: '/user',
      component: '../layouts/UserLayout',
      routes: [
        {
          name: 'login',
          path: '/user/login',
          component: './user/login/Login',
        },
        {
          name: 'register',
          path: '/user/register',
          component: './user/register/Register',
        },
        {
          component: '404',
        },
      ],
    },
    {
      path: '/',
      component: '../layouts/SecurityLayout',
      routes: [
        {
          path: '/',
          component: '../layouts/BasicLayout',
          routes: [
            {
              path: '/',
              redirect: '/index',
            },
            {
              path: '/index',
              name: 'home',
              icon: 'smile',
              component: './Index',
            },
            {
              path: '/index/admin',
              name: 'home',
              icon: 'smile',
              component: './AdminIndex',
              hideInMenu: true,
            },
            // {
            //     path: '/admin',
            //     name: 'admin',
            //     icon: 'crown',
            //     component: './Admin',
            // },
            {
              name: 'account',
              icon: 'user',
              path: '/account',
              hideInMenu: true,
              routes: [
                {
                  name: 'center',
                  icon: 'smile',
                  path: '/account/center',
                  component: './management/account/AccountCenter',
                },
              ],
            },
            // {
            //     path: 'admin/manage',
            //     icon: 'table',
            //     name: 'manage',
            //     routes: [
            //         // 管理员账户管理
            //         {
            //             path: 'admin/manage/account',
            //             name: 'account',
            //             icon: 'team',
            //             component: './management/account/AdminAccount',
            //         },
            //         // 管理员电梯管理
            //         {
            //             path: 'admin/manage/elevator',
            //             name: 'elevator',
            //             icon: 'profile',
            //             component: './management/elevator/AdminElevator',
            //         },
            //         // 管理员询价管理
            //         {
            //             path: 'admin/manage/inquiry',
            //             name: 'inquiry',
            //             icon: 'file-protect',
            //             component: './management/inquiry/AdminInquiry',
            //         },
            //         // 管理员询价详情
            //         {
            //             path: 'admin/manage/inquiry/detail',
            //             name: 'inquiryDetail',
            //             icon: 'file-protect',
            //             hideInMenu: true,
            //             component: './management/inquiry/AdminInquiryDetail',
            //         },
            //         // 管理员投保管理
            //         {
            //             path: 'admin/manage/insurance',
            //             name: 'insurance',
            //             icon: 'insurance',
            //             component: './management/insurance/AdminInsurance',
            //         },
            //         {
            //             component: '404',
            //         },
            //     ]
            // },
            // {
            //     path: '/manage',
            //     icon: 'table',
            //     name: 'manage',
            //     routes: [
            //         // 账户管理
            //         {
            //             path: '/manage/account',
            //             name: 'account',
            //             icon: 'team',
            //             component: './management/account/Account',
            //         },
            //         // 电梯管理
            //         {
            //             path: '/manage/elevator',
            //             name: 'elevator',
            //             icon: 'profile',
            //             component: './management/elevator/Elevator',
            //         },
            //         // 询价管理
            //         {
            //             path: '/manage/inquiry',
            //             name: 'inquiry',
            //             icon: 'file-protect',
            //             component: './management/inquiry/Inquiry',
            //         },
            //         // 询价详情
            //         {
            //             path: '/manage/inquiry/detail',
            //             name: 'inquiryDetail',
            //             icon: 'file-protect',
            //             hideInMenu: true,
            //             component: './management/inquiry/InquiryDetail',
            //         },
            //         // 投保管理
            //         {
            //             path: '/manage/insurance',
            //             name: 'insurance',
            //             icon: 'insurance',
            //             component: './management/insurance/Insurance',
            //         },
            //         {
            //             component: '404',
            //         },
            //     ]
            // },
            {
              // 客户管理
              path: '/customer',
              icon: 'customer',
              name: 'customer',
              component: './customer/customer',
            },
            {
              // 运营商管理
              path: '/operator',
              icon: 'operator',
              name: 'operator',
              component: './operator/operator',
            },
            {
              // 楼盘管理
              path: '/hourse',
              icon: 'hourse',
              name: 'hourse',
              component: './hourse/hourse',
            },
            {
              //电梯管理
              path: '/elevator',
              icon: 'elevator',
              name: 'elevator',
              component: './elevator/elevator',
            },
            {
              path: '/point',
              icon: 'ellipsis',
              name: 'point',
              routes: [
                // 点位管理
                {
                  path: '/point/point',
                  name: 'point',
                  icon: 'aliwangwang',
                  component: './point/point',
                },
                // 点位编辑
                {
                  path: '/point/editPoint',
                  name: 'editPoint',
                  icon: 'aliwangwang',
                  component: './point/editPoint',
                },
              ],
            },
              {
                  path: '/deviceLog/showDeviceLog',
                  icon: 'play-circle',
                  name: 'deviceLog',
                  component: './deviceLog/showDeviceLog',
                  hideInMenu: true,
              },
            {
              path: '/journal',
              icon: 'play-circle',
              name: 'journal',
              routes: [
                // 期刊管理
                {
                  path: '/journal/journal',
                  name: 'journal',
                  component: './journal/journal',
                },
                // 期刊编辑
                {
                  path: '/journal/editJournal',
                  name: 'editJournal',
                  component: './journal/editJournal',
                },
              ],
            },
            {
              // App更新管理
              path: '/appUp',
              icon: 'appUp',
              name: 'appUp',
              component: './appUp/appUp',
            },
              // 公告
              {
                  path: '/noticeLook',
                  name: 'noticeLook',
                  icon: 'noticeLook',
                  component: './settings/notice/noticeLook',
              },
            {
              path: '/settings',
              icon: 'setting',
              name: 'settings',
              routes: [
                // 系统用户
                {
                  path: '/settings/user/systemUser',
                  name: 'systemUser',
                  icon: 'aliwangwang',
                  component: './settings/user/systemUser',
                },
                // 角色管理
                {
                  path: '/settings/user/role',
                  name: 'role',
                  icon: 'team',
                  component: './settings/user/role',
                },
                // 系统菜单
                {
                  path: '/settings/menu/systemMenu',
                  name: 'systemMenu',
                  icon: 'bars',
                  component: './settings/menu/systemMenu',
                },
                // 按钮管理
                {
                  path: '/settings/menu/menuButtons',
                  name: 'menuButtons',
                  icon: 'bars',
                  component: './settings/menu/menuButtons',
                },
                // 菜单、按钮权限
                {
                  path: '/settings/menu/menuRight',
                  name: 'menuRight',
                  icon: 'share-alt',
                  component: './settings/menu/menuRight',
                },
                // 通知设置
                {
                  path: '/settings/notification',
                  name: 'notification',
                  icon: 'notification',
                  component: './settings/notification/Notification',
                },
                // app全局配置
                {
                  path: '/settings/appConfig',
                  name: 'appConfig',
                  icon: 'appConfig',
                  component: './settings/appConfig/appConfig',
                },
                  // 系统参数设置
                  {
                      path: '/settings/sysParams',
                      name: 'sysParams',
                      icon: 'sysParams',
                      component: './settings/sysParams/sysParams',
                  },
                  // 公告管理
                  {
                      path: '/settings/notice',
                      name: 'notice',
                      icon: 'notice',
                      component: './settings/notice/notice',
                  },
                {
                  component: '404',
                },
              ],
            },
            {
              component: './404',
            },
          ],
        },
        {
          component: './404',
        },
      ],
    },
    {
      component: './404',
    },
  ],
  // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  theme: {
    // ...darkTheme,
    'primary-color': '#21BA63',
  },
  define: {
    ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
      ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。
  },
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
  disableRedirectHoist: true,
  cssLoaderOptions: {
    modules: true,
    getLocalIdent: (context, _, localName) => {
      if (
        context.resourcePath.includes('node_modules') ||
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
      ) {
        return localName;
      }

      const match = context.resourcePath.match(/src(.*)/);

      if (match && match[1]) {
        const antdProPath = match[1].replace('.less', '');
        const arr = slash(antdProPath)
          .split('/')
          .map(a => a.replace(/([A-Z])/g, '-$1'))
          .map(a => a.toLowerCase());
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }

      return localName;
    },
  },
  manifest: {
    basePath: '/',
  }, // chainWebpack: webpackPlugin,
  proxy: {
    '/api': {
      // target: 'http://shaw.com:8842',
      // target: 'https://policy-api-test.xiaobaibao.com',
      // target: 'https://admin.yfkj-vip.com', //生产环境配置
      target: 'http://114.67.82.19:8081',
      // target: 'http://127.0.0.1:9022',
      changeOrigin: true,
      pathRewrite: { '^/api': '/' },
    },
  },
};
